﻿using System;
using System.Windows;
using FeatureDemo.Helper;
using Microsoft.Phone.Controls;

namespace FeatureDemo.Features.Browser
{
    [Feature("Script Notify", "Demonstrates how the Website can interact with Windows Phone", 7.5)]
    public partial class ScriptNotifyPage : PhoneApplicationPage
    {
        public ScriptNotifyPage()
        {
            InitializeComponent();

            this.Loaded += (s, e) =>
            {
                DoIt();
            };
        }

        private void DoIt()
        {
            try
            {
                string path = "Features/Browser/ScriptNotify.htm";
                string html = Tools.LoadTextFileFromResource(path);

                _webBrowser.IsScriptEnabled = true;
                _webBrowser.NavigateToString(html);
                _webBrowser.ScriptNotify += (s, e) =>
                {
                    MessageBox.Show(e.Value);
                };
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
    }
}